package com.ihr360.excel.type;

public enum ProgressStep {

    UPLOAD("上传", "40"),
    PARSE("解析", "65"),
    FINISH("完成", "100");

    private String title;

    private String progress;

    ProgressStep(String title, String progress) {
        this.title = title;
        this.progress = progress;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getProgress() {
        return progress;
    }

    public void setProgress(String progress) {
        this.progress = progress;
    }

    public static Integer getCurrentStep(int progress) {
        if (progress <= Integer.parseInt(UPLOAD.getProgress())) {
            return 1;
        } else if (progress > Integer.parseInt(UPLOAD.getProgress()) && progress <= Integer.parseInt(PARSE.getProgress())) {
            return 2;
        } else {
            return 3;
        }
    }

    public static String getStepProgress(int progress) {

        String stepPropress = "0";
        int currentStep = getCurrentStep(progress);
        if (currentStep == 1) {
            if (Integer.parseInt(UPLOAD.getProgress()) <= progress) {
                stepPropress = "100";
            } else {
                stepPropress = Math.round(progress * 100 / Integer.parseInt(UPLOAD.getProgress())) + "";
            }
        } else if (currentStep == 2) {
            if (Integer.parseInt(PARSE.getProgress()) <= progress) {
                stepPropress = "100";
            } else {
                stepPropress = Math.round(progress * 100 / Integer.parseInt(PARSE.getProgress())) + "";
            }
        } else {
            if (Integer.parseInt(FINISH.getProgress()) <= progress) {
                stepPropress = "100";
            } else {
                stepPropress = progress + "";
            }
        }
        return stepPropress;
    }

}
